package org.hawkular.datamining.forecast.utils;

import org.joda.time.*;

public final class JodaUtils {
	private static final JodaTimeUnit converter = JodaTimeUnit.MILLISECONDS;

	private JodaUtils() {
	}

	public static int size(ReadableDuration duration, ReadablePeriod period) {
		return size(converter.convert(duration), converter.convert(period));
	}

	public static int size(ReadableInterval interval, ReadablePeriod period) {
		return size(converter.convert(interval), converter.convert(period));
	}

	public static int size(ReadablePeriod interval, ReadablePeriod period) {
		return size(converter.convert(interval), converter.convert(period));
	}

	public static int size(long interval, long period) {
		return (int) (interval / period);
	}

	public static int idx(ReadableDateTime base, ReadableDateTime curr, ReadablePeriod period) {
		return size(converter.convert(new Duration(base, curr)), converter.convert(period));
	}

	public static int idx(LocalTime time, ReadablePeriod period) {
		return size(converter.convert(time), converter.convert(period));
	}
}
